<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="func" uri="http://www.zz.com/tag" %>
<%@ tag pageEncoding="UTF-8" %>
<%@ attribute name="selectId" required="true" rtexprvalue="true" description="select的id，当前界面必须唯一" %>
<%@ attribute name="property" required="false" rtexprvalue="true" description="input的name，当前界面必须唯一" %>
<%@ attribute name="groupId" required="true" rtexprvalue="true" description="字典组的id" %>
<%@ attribute name="selectItemKey" required="false" rtexprvalue="true" description="默认选择的字典key" %>


<c:set var="basePath" value="${pageContext.request.contextPath}"/>
<script type="text/javascript" src="${basePath}/js/multiselect/jquery.multiselect.js"></script>
<link rel="stylesheet" type="text/css" href="${basePath}/js/multiselect/jquery.multiselect.css"/>
<style>

</style>
<input type="hidden" name="${property}" data-cust-type="multiselect" data-relate-id="${selectId}_multiselect" value="${selectItemKey}">

<select id="${selectId}" multiple="multiple" data-relate-id="${property}">

<c:forEach var="item" items="${func:dictGroup(groupId)}">
<option value="${item.itemKey}">
    ${item.itemKey}/${item.itemValue}
</option>
</c:forEach>
</select>

<script>
    $(function () {

        var codes = '${selectItemKey}'.split(',');
        for(var i=0; i<=codes.length-1;i++)
        {
            if(codes[i] == '')
            {
                continue;
            }
            $("select[id='${selectId}']>option[value='" + codes[i] + "']").attr("selected",
                    true);

        }
        $("select[id='${selectId}']").multiselect({
            header: true, height: 200, selectedList: 10,//预设值最多显示10被选中项
            noneSelectedText: "请选择", checkAllText: "全选", uncheckAllText: '全不选', //            hide: ["explode", 500],
            close: function () {
                var values = $("select[id='${selectId}']").val();
                $("input[name='${property}']").val(values);
                if(typeof  _validator != 'undefined' && _validator)
                {
                    _validator.element($("input[name='${property}']"))
                }
            }
        });
    });
</script>
